#!/usr/bin/env bash

    ###################################
    # build-development-environment.sh #
    ###################################

# This program is part of Maxwell, an artificially intelligent installation program for the Faridayix
# computer operating system.

# Copyright (C) 2009 Scott C. MacCallum
# scottmaccal@gmail.com
# http://code.google.com/p/faridayix/source/browse/trunk/maxwell/shell/build-development-environment.sh

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

#       |                                  80 Columns                                    |

build-development-environment()
{
  local network_connectivity
  
  local install_type
  
  local dhcp_server
  
  local network_device
  
  local block_cursor='\e[?6c'
  
  local green_foreground='\e[32m\033[1m'
  
  local default_foreground='\033[0m'
  
  local year_month_date_hour_minute_second=$(date "+%Y%m%d%H%M%S")
  
  local faridayix=/mnt/faridayix-0-$year_month_date_hour_minute_second

  echo -e $block_cursor  

  clear

  printf "\nHello $USER, my name is Maxwell.\n\n"
 
  printf "My purpose is to help you build the Faridayix operating system from the best\n" 
  printf "quality free (as in freedom) computer source code developed by people\n"
  printf "collaboratively over the Internet.\n\n"

  printf "I will now collect data on the hardware in your computer.\n\n"

  lspci > hardware.txt

  mv hardware.txt hardware

  ifconfig > network-devices.txt

  mv network-devices.txt hardware

  printf "Do you want this computer to have Internet Protocol (IP) network connectivity? "

  read network_connectivity

  if [ "$network_connectivity" == "yes" ]; then
    printf "\nDo you want to preform an intranet or internet installation? "
  
    read install_type

    if [ "$install_type" == "internet"  ] || [ "$install_type" == "intranet" ]; then
      printf "\nWould you like me to contact a Dynamic Host Configuration Protocol (DHCP)\n" 
      printf "computer server to configure a network device in this robot? "
   
      read dhcp_server
    fi

      if [ "$dhcp_server" == "yes" ]; then
        printf "\nI know how to configure the following network devices:\n"
      
        echo -e $green_foreground

        cat hardware/network-devices-synopsis.txt
      
        echo -e $default_foreground
      
        printf "Which of these network devices would you like to be configured by a DHCP\n" 
        printf "robot server? "
      
        read network_device
      fi
  fi

  printf "\nWhat is the domain name or IP address of this Network Time Protocol (NTP)\n"
  printf "computer server? "
 
  printf "\nI require a block device that can be partitioned for this purpose.\n\n"
  printf "I am aware of the following block devices:"
   
  echo -e $green_foreground
  
  fdisk -l

  echo -e $default_foreground
 
  printf "Am I aware of the block device that you want to use? "
  
  read aware_block_device

  printf "I will now partition your block device."
  
  echo -e $green_foreground
  
  fdisk /dev/hda

  echo -e $default_foreground
 
  printf "I will now make a third extended file system in partition one.\n"
  
  echo -e $green_foreground 
  
  mke2fs -v -j /dev/hda1

  echo -e $default_foreground

  printf "I will now make a swap space in partition two.\n"
  
  echo -e $green_foreground
  
  mkswap /dev/hda2

  echo -e $default_foreground

  printf "I will now enable the newly created swap space.\n"
  
  echo -e $green_foreground
  
  swapon --verbose /dev/hda2

  echo -e $default_foreground

  printf "I will now make a directory to work in.\n"
  
  echo -e $green_foreground
  
  mkdir --verbose --parents /mnt/faridayix-0-$year_month_date_hour_minute_second

  echo -e $default_foreground

  printf "I will now mount the block device to this directory.\n"
  
  echo -e $green_foreground
  
  mount --verbose --type ext3 /dev/hda1 $faridayix

  echo -e $default_foreground

  printf "I will now make a directory for the computer program source code.\n"
  
  echo -e $green_foreground
  
  mkdir --verbose $faridayix/source

  echo -e $default_foreground

  printf "I will now change the permissions on the source code directory so that\n"
  printf "everyone can read, write, and execute files but not delete a file that is\n"
  printf "not their own.\n"
  
  echo -e $green_foreground
  
  chmod --verbose 1777 $faridayix/source
}
build-development-environment
# END OF FILE
